
from playwright.sync_api import sync_playwright,expect
from time import sleep
from data import db
import time

sql=db("root","yidong666","10.59.9.12","a3mall")
def test_A3mall_01():
    print("开始")
#初始化框架并启动后台
    with sync_playwright()as p:
        # 执行搜索的语句（放哪都行）数据库断言1
        ye = sql.select('select amount from mall_users where username = "13811033962"')
        print(ye[0][0])
        #打开浏览器p.firefox.launch
        #不要无头模式headless=False
        browser=p.firefox.launch(headless=False)
        #打开新的页面
        page=browser.new_page()
        #访问目标网址
        page.goto('http://10.59.9.12:7001/')
        #进行操作
        #点击去登录
        page.click('xpath = /html/body/div[1]/div/div[2]/ul/li[1]/a')
        time.sleep(4)
        #输入账号密码
        page.fill('xpath = //*[@id="theForm"]/div[1]/span[2]/input','13811033962')
        page.fill('xpath = //*[@id="theForm"]/div[2]/span[2]/input','123456')
        time.sleep(15)
        #点击登录按钮
        page.click('xpath = //*[@id="theForm"]/div[5]/a')
        time.sleep(5)
        # 断言,登陆成功：欢迎回来
        dy1 = page.locator('xpath = /html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]').text_content()
        print("登录成功断言：", dy1)
        # 数据库断言余额
        dy2 = page.locator('xpath = /html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]/span').text_content()
        print(dy2.replace('¥ ', ''))
        print("账户余额断言：", dy2)
        # 进行判断（断言正确跑完全程，错误的话进行报错）
        assert float(dy2.replace('¥ ', '')) == float(ye[0][0])
    print("结束")